﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreesenseSubAIS.Core
{
    public class ETSHelper
    {
        private ETSDemo _ETSUnit = null;
        private int _picindex;
        public int PixIndex
        {
            get
            {
                if (_picindex > _ETSUnit.ETSImagesCount)
                    _picindex = 0;
                else _picindex += 1;
                return _picindex;
            }
        }
        public bool OpenService(string productname)
        {
            bool bResult = true;
            try
            {
                CloseService();
                _ETSUnit = new ETSDemo();
                _ETSUnit.Name = productname;
                _ETSUnit.OnMessageCallback += _ETSUnit_OnMessageCallback;
                bool initResult = _ETSUnit.Init();
                if (!initResult)
                {
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                System.Windows.Forms.MessageBox.Show("启动失败:" + ex.Message);
            }
            return bResult;
        }

        private void _ETSUnit_OnMessageCallback(object sender, string e)
        {
            //Utility.ShowInformation("ETS返回信息:" + e);
        }

        public bool CloseService()
        {
            bool bResult = true;
            try
            {
                if (_ETSUnit != null)
                {
                    _ETSUnit.Close();
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                System.Windows.Forms.MessageBox.Show("关闭失败:" + ex.Message);
            }
            return bResult;
        }
        public void ChangeColor(int index)
        {
            if (_ETSUnit != null)
            {
                _ETSUnit.SwitchImages(index);
                _picindex = index;
            }
        }
        public void ShotDown()
        {
            if (_ETSUnit != null)
                _ETSUnit.ShutDown();
        }
        public bool PowerOn()
        {
            if (_ETSUnit != null)
                return _ETSUnit.PowerON();
            return false;
        }
    }
}
